<template>
    <rui-page :defines="defines">
        <Row>
            <rui-query :label-width="120"
                       :query="queryExceptionData"
                       :query-rows="queryRows"
                       ref="exceptionQuery"
            />
        </Row>
        <rui-table :defineId="'flowException'"
                   :fixedLeft="['serviceId','afsFlowKey','bizDataId']"
                   :columns="['serviceId','afsFlowKey','bizDataId','flowInstanceId','gwtMsgTypeName','gwtObjectCodeName','action']"
                   :fixedRight="['action']"

                   :showIndex="false"
                   :select="false"
                   :slots="[{key:'action',slot:'action'}]"
                   @loadDatas="queryExceptionData"
                   ref="exceptionTable"
                   ref-query="exceptionQuery">
            <template slot="action" slot-scope="{ row }">
                <div>
                    <Button @click="processException(row)" size="small" type="error">处理异常</Button>
                </div>
            </template>
        </rui-table>
    </rui-page>
</template>

<script>
    import flowException from "./defines/flow-exception-define";
    import {listException, resolverException} from "_p/basic/api/flowconfig/flow-exception"

    export default {
        name: "flow-flowException",
        data() {
            return {
                defines: [],
                queryRows: [
                    {
                        defineId: 'flowException',
                        totalSpan: 16,
                        fields: ['afsFlowKey', 'bizDataId']
                    }
                ],
            }
        },
        methods: {
            queryExceptionData(queryData) {
                listException(queryData).then(res => {
                    if (res.code === "0000") {
                        let {records, total} = res.data;
                        this.$refs.exceptionTable.updateTableData(records, total);
                    }
                });
            },
            processException(row) {
                let self = this;
                this.$Modal.confirm({
                    title: "确认",
                    content: '处理该笔异常？',
                    onOk: () => {
                        resolverException(row).then(res => {
                            if(res.code=='0000'&&res.data){
                                this.$Message.info("异常处理成功");
                            }else{
                                this.$Message.error("异常解决失败");
                            }
                            self.$refs['exceptionTable'].reloadData();
                        })
                    }
                });
            },
        },
        computed: {
        },
        created(){
            this.defines.push({
                id: 'flowException',
                fields: flowException
            })
        },
        mounted() {
            this.$refs['exceptionTable'].reloadData();
        }
    };
</script>
